package com.android.qjpmc.application_module.viewModel;

import com.android.qjpmc.application_module.contract.StationContract;
import com.android.qjpmc.application_module.home.model.StationDataModel;
import com.android.qjpmc.bean.PointParameterBean;
import com.android.qjpmc.bean.PwrDeviceBean;
import com.android.qjpmc.bean.StationDataBean;
import com.android.qjpmc.data_module.PwrDataModule;
import com.android.qjpmc.widget.mvvm.factory.CreateModel;
import com.android.qjpmc.widget.retrofithelper.rxsubscriber.ProgressObserver;

import java.util.List;

@CreateModel(StationDataModel.class)
public class StationViewModel extends StationContract.ViewModel {
    public void getGroupListOfStation(String stationId) {
        /*
        int nStationID = 0;
        nStationID = Integer.parseInt(stationId);
        int count = PwrDataModule.getInstance().GetStationDeviceCount(nStationID);
        if (count > 0 )0
        {
            List<StationGroupBean>  DeviceList = PwrDataModule.getInstance().GetStationDeviceBeanList(nStationID);
            returnStationData(DeviceList);
        }*/
        mView.showLoading("");
        mModel.getGroupListOfStation(stationId).subscribe(new ProgressObserver<List<PwrDeviceBean>>(false, this) {
            @Override
            public void _onNext(List<PwrDeviceBean> pwrDeviceBeans) {
                int nStationID = 0;
                nStationID = Integer.parseInt(stationId);
                //todo 胖胖修改: 数据不统一 注释掉了
               // PwrDataModule.getInstance().CreateAllPowerDeviceOfAStation(nStationID, pwrDeviceBeans);
                returnStationData(pwrDeviceBeans,stationId);

            }
        });
    }

    private void returnStationData(List<PwrDeviceBean> pwrDeviceBeans, String stationId) {
        StationDataBean data = new StationDataBean();
        for (PwrDeviceBean pwrDeviceBean : pwrDeviceBeans) {
            pwrDeviceBean.stationId=stationId;
        }
        data.stationGroupList = pwrDeviceBeans;
        mView.showContent(data);
    }

    @Override
    public void getPointListOfGroup(String stationId, List<PwrDeviceBean> pwrDeviceBeans) {
        mModel.getPointListOfGroup(pwrDeviceBeans.get(0).groupId, 1).subscribe(new ProgressObserver<List<PointParameterBean>>(false, this) {
            @Override
            public void _onNext(List<PointParameterBean> groupPointListBean) {
            }
        });

    }
}
